<?php
	session_start();
	require_once '../setting/kon.php';
	$ses = $_SESSION['id_session'];
	$id = $_POST['id_produk'];
	$ukuran = $_POST['ukuran'];
	$jumlah = $_POST['jumlah'];
	$diskon = $_POST['diskon'];
	
	if ($ukuran != ""){
		$cek = $koneksi->query("select id_produk from order_temp where id_produk = '$id' and id_session = '$ses' and id_ukuran = '$ukuran'"); echo "a";
	}else{
		$cek = $koneksi->query("select id_produk from order_temp where id_produk = '$id' and id_session = '$ses'"); echo "b";
	}
	$jml = $cek->rowCount();

	$data = $koneksi->query("select * from produk where id_produk = $id");
	$hasil = $data->fetch(PDO::FETCH_ASSOC);
	
	$harga = $hasil['harga'];
	
	if($jml == 0){
		if ($ukuran==""){
			$sttmt = $koneksi->exec("insert into order_temp(id_produk,id_session,jumlah,id_ukuran,harga,diskon) values ('$id','$ses',$jumlah,1,$harga,$diskon)");
		}else {
			$sttmt = $koneksi->exec("insert into order_temp(id_produk,id_session,jumlah,id_ukuran,harga,diskon) values ('$id','$ses',$jumlah,$ukuran,$harga,$diskon)"); echo "e";
		}	
	}else{
		if ($ukuran != ""){
			$sql = $koneksi->exec("update order_temp set jumlah = jumlah + $jumlah, harga = $harga, diskon = $diskon where id_produk = '$id' and id_session = '$ses' and id_ukuran = '$ukuran'"); echo "f";
		}else{
			$sql = $koneksi->exec("update order_temp set jumlah = jumlah + $jumlah, harga = $harga, diskon = $diskon where id_produk = '$id' and id_session = '$ses'"); echo "g";
		}
	}
?>